#include "TcpServer.hpp"
#include "Http.hpp"

HttpResponse Login(HttpRequest& req)
{
    std::cout << "外部拿到参数"<<std::endl;
    req.GetBodytext();
    std::cout << "######################"<<std::endl;
    HttpResponse resp;
    //resp.AddHeader("Set-Cookie", "username=lxp; expires=Sat,27 Jul 2024 11:02:00 UTC;");
    //resp.AddHeader("Set-Cookie", "passwd=1232345;");
    resp.AddBodyText("<html><h1>result done!</h1></html>");
    resp.AddCode(200,"OK");
    return resp;
}

int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        LOG(ERROR,"./tcpserver serverport\n");
        exit(2);
    }
    uint16_t localport = std::stoi(argv[1]); 
    
    HttpServer hserver;
    hserver.AddService("/login",Login);

    std::unique_ptr<TcpServer> server = std::make_unique<TcpServer>(
        std::bind(&HttpServer::HandlerHttpRequest,&hserver,std::placeholders::_1),
        localport);
    
    server->Loop();

    return 0;
}